/**
 * 
 */
package niuke;

import java.util.Scanner;

/**
 * @author zhongfang
 *
 */
public class baoguoyunshu {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int[] count = new int[6];
		for (int i = 0; i < 6; i++) {
			count[i] = scanner.nextInt();
		}

		while (!allZero(count)) {
			int sum = 0;
			sum += count[5];

			sum += count[4];// 放5*5,还可以放1*1共9个
			count[0] = Math.max(0, count[0] - count[4] * 9);

			sum += count[3];// 放4*4,还可以放5个2*2+16个1*1；或者20个1*1
			// 放5个
			int tmp1 = count[1];// 原来2*2的个数
			count[1] = Math.max(0, count[1] - count[3] * 5);// 最多可以放5个2*2
			// 剩下1-4个2*2
			int x = count[3] - tmp1 / 5;// x剩余的空间
			int y = count[1] % 5;
			if (y != 0 && x > 0) {// 还有2*2要放y个
				count[0] -= (36 - 16 - y * 4);
				count[0] = Math.max(0, count[0]);
				x--;
			}
			// 单独放1*1
			if (x > 0) {
				count[0] -= 20 * (x);
				count[0] = Math.max(0, count[0]);
			}

			// 放3*3
			sum += (count[2] / 4);// 放完整的4个
			tmp1 = count[2] % 4;
			if (tmp1 != 0) {
				sum++;
				int twoPut = 0;
				int onePut = 0;
				switch (tmp1) {
				case 1:
					// 能放5个2+7个1,4个2.。。
					twoPut = Math.min(count[1], 5);
					onePut = 36 - 9 - twoPut * 4;
					break;
				case 2:
					// 最多能放3个2
					twoPut = Math.min(count[1], 3);
					onePut = 36 - 18 - twoPut * 4;
					break;
				case 3:
					// 最多能放1个2
					twoPut = Math.min(count[1], 1);
					onePut = 36 - 27 - twoPut * 4;
					break;
				}
				// 放的1的个数是剩余的面积
				count[0] -= onePut;
				count[0] = Math.max(0, count[0]);
			}

			sum += count[0] / 36;
			if (count[0] % 36 != 0) {
				sum++;
			}
			System.out.println(sum);
			for (int i = 0; i < 6; i++) {
				count[i] = scanner.nextInt();
			}
		}
	}

	private static boolean allZero(int[] count) {
		for (int i = 0; i < count.length; i++) {
			if (count[i] != 0)
				return false;
		}
		return true;
	}

}
